<?php

class BcLibStandardFunctions implements CliLibrary
{
	private static $functions = array(
		'floor' => 'f_floor',
		'sqrt' => 'f_sqrt',
	);

	public static function addLibrary (CliMode $mode)
	{
		$mode->addFunctions(__CLASS__, self::$functions);
	}

	public static function f_floor (ArgContext $args)
	{
		$args->requireTypes('modenumber');
		$number = $args->toModeNumber(0)->get();
		if (strpos($number, '.') !== false)
		{
			$number = substr($number, 0, strpos('.'));
		}

		return new BcModeNumber($number);
	}

	public static function f_sqrt (ArgContext $args)
	{
		$args->requireCount(1);
		return new BcModeNumber(bcsqrt($args->toModeNumber(0)));
	}
}
?>